//
//  HeaderView.m
//  YiChe
//
//  Created by 蒋杏飞 on 15/8/8.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "HeaderView.h"
#import "ListModel.h"
#import "UIImageView+WebCache.h"
// 就是创建scrollview，前期没有数据

@interface HeaderView ()
@property (nonatomic, retain) UIScrollView *scroll;
@end

@implementation HeaderView

- (void)dealloc
{
    [_scroll release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createScroll];
    }
    return self;
}
- (void)createScroll
{
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    _scroll.contentSize = CGSizeMake(_scroll.frame.size.width * 4, 0);
    _scroll.pagingEnabled = YES;
    [self addSubview:_scroll];
    [_scroll release];
}

- (void)setImageWithModels:(NSArray *)array
{
    
    for (int i = 0; i < 4; i++) {
        ListModel *model = [array objectAtIndex:i];
        
        NSString *url = model.picCover;
        url = [url stringByReplacingOccurrencesOfString:@"{0}" withString:@"700"];
        url = [url stringByReplacingOccurrencesOfString:@"{1}" withString:@"350"];
        model.picCover = url;
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.scroll.frame.size.width, 0, self.scroll.frame.size.width, self.scroll.frame.size.height)];
        image.backgroundColor = [UIColor cyanColor];
        [image sd_setImageWithURL:[NSURL URLWithString:model.picCover] placeholderImage:nil];
        [self.scroll addSubview:image];
        [image release];
    }
}

@end








